package com.audaque.springboot.foshanupload.web.consuldemo.controller;


import com.audaque.springboot.foshanupload.authcore.anno.NeedLoginAnno;
import com.audaque.springboot.foshanupload.web.consuldemo.properties.ConsulTestProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @author zgb
 * @desc ...
 * @date 2022-04-17 19:05:42
 */
@Slf4j
@RefreshScope
@RestController
@RequestMapping("consul")
public class ConsulController {
    //微服务springcloud 动态配置需要使用@RefreshScope，如果数据库需要动态配置，则不能使用数据库自动配置，需要手动创建数据源bean并加上@RefreshScope
    @Autowired
    ConsulTestProperties consulTestProperties;


    @Value("${consultest.desc}")
    private String desc;

    @GetMapping("/sessionId")
    public String sessionId(@RequestHeader String sessionId) {
        return sessionId;
    }

    @NeedLoginAnno
    @GetMapping("/testConsulTestProperties")
    public String testConsulTestProperties() {
        return consulTestProperties.getDesc();
    }

    @NeedLoginAnno
    @GetMapping("/testValue")
    public String testValue() {
        return desc;
    }


    @GetMapping("bad_gateway")
    @ResponseStatus(HttpStatus.BAD_GATEWAY)
    public String shouldBadGateway() throws InterruptedException {
        log.debug("<-- GET: bad_gateway ...");
        return "bad gateway";
    }

}
